using System;
using System.Data;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebForum
{
    public class Common
    {
        public static string HashMD5(string input)
        {
            MD5 md5 = MD5.Create();
            byte[] inputBytes = Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }
        public static string PhysicalApplicationPath()
        {
            return HttpContext.Current.Request.PhysicalApplicationPath;
        }
        public static int ParseInt32(string i)
        {
            try
            {
                return Int32.Parse(i);
            }
            catch (Exception)
            {
                return -1;
            }
        }
        public static DateTime ParseDateTime(string date)
        {
            try
            {
                return DateTime.Parse(date);
            }
            catch (Exception)
            {
                return DateTime.Now;
            }
        }
        public static void Show(string sMessage)
        {
            HttpContext.Current.Response.Write("<script language='javascript'>window.alert('" + sMessage +
                                               "');</script>");
        }

        public static void Show(string sMessage, string url)
        {
            HttpContext.Current.Response.Write("<script language='javascript'>window.alert('" + sMessage +
                                               "');window.location.href='" + url + "';</script>");
        }
        public static string RemoveSpecialChars(string input)
        {
            return Regex.Replace(input, @"[^0-9a-zA-Z\._]", string.Empty);
        }
    }
}
